package com.woke.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.netease.nim.uikit.GlideApp;
import com.woke.data.Data_zhongchou;
import com.zhongcai.online.R;

import java.util.ArrayList;
import java.util.List;

import cn.xl.xxl.imagecache.ImageLoader;

public class Zhouchouadter extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<Data_zhongchou> datalist;
	private ImageLoader imageLoader;
	private int getphonewihd;

	public Zhouchouadter(LayoutInflater minflater, ArrayList<Data_zhongchou> datalist, ImageLoader imageLoader, int getphonewihd) {
		this.mInflater = minflater;
		this.datalist = datalist;
		this.imageLoader = imageLoader;
		this.getphonewihd = getphonewihd;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datalist.size ();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	class Holder {
		TextView mTpeople;
		TextView mTname;
		TextView mTmoney;
		TextView mTinfo_info;
		TextView mTinfo;
		ImageView mImage1;
		ProgressBar mBar;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if (convertView == null) {
			holder = new Holder ();
			convertView = mInflater.inflate (R.layout.item_adater_zhongchou, null);
			holder.mImage1 = (ImageView) convertView.findViewById (R.id.zchou_image_left);
			holder.mBar = (ProgressBar) convertView.findViewById (R.id.zchou_progress);
			holder.mTname = (TextView) convertView.findViewById (R.id.zchou_text_name);
			holder.mTinfo = (TextView) convertView.findViewById (R.id.zchou_text_info);
			holder.mTinfo_info = (TextView) convertView.findViewById (R.id.zchou_text_info_info);
			holder.mTmoney = (TextView) convertView.findViewById (R.id.zchou_text_money);
			holder.mTpeople = (TextView) convertView.findViewById (R.id.zchou_text_people);
			convertView.setTag (holder);
		} else {
			holder = (Holder) convertView.getTag ();
		}

		LayoutParams params = holder.mImage1.getLayoutParams ();
		params.width = getphonewihd / 7 * 3;
		params.height = getphonewihd / 7 * 2;
		holder.mImage1.setLayoutParams (params);
		Data_zhongchou data = datalist.get (position);
		holder.mTname.setText (data.product_name);
		holder.mTinfo.setText (data.product_name);
		holder.mTmoney.setText (data.money + "元");
		holder.mTpeople.setText (data.count + "人");
		holder.mBar.setProgress (data.percent * 100);
		if (! TextUtils.isEmpty (data.product_img)) {
			if (data.product_img.startsWith ("http")) {
				GlideApp.with (convertView.getContext ()).load (data.product_img).placeholder(R.mipmap.icn__launch_oem)
						.error(R.mipmap.icn__launch_oem).into (holder.mImage1);
			} else {
				GlideApp.with (convertView.getContext ()).load ("http://" + data.product_img).placeholder(R.mipmap.icn__launch_oem)
						.error(R.mipmap.icn__launch_oem)
					.into (holder.mImage1);
			}
		}
//		imageLoader.DisplayImage("http://"+data.product_img, holder.mImage1, false, false, false,0);
		return convertView;
	}

}
